<template>
	<view class="content">
					<image class="headicon" :src="userinfo.headicon"></image>
					<text>{{userinfo.name}}</text>
					<view class="text-area">
						<button v-if="!flag" type="primary" @click="toLogin">点击登录</button></view>
					<view class="button">
						<button type="primary" :disabled="!flag" size="default" @click="logout">退出</button>
				</view>
				<view class="entry-wrapper">
					<view>
						<image src="../../static/留言.png"></image>我的留言
					</view>
					<view>
						<image src="../../static/评论.png"></image>我的评论
					</view>
					<view>
						<image src="../../static/收藏.png"></image>我的收藏
					</view>
				</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: {
									userid: '001',
									username: 'andmin',
									headicon: '../../static/等雨停.jpg',
									},
									flag: false
			}
		},
		onShow() {
			uni.getStorage({
				key: "userinfo",
				success: (res) => {
					uni.showToast({
						title: '已登录'
					});
					this.flag = true
					this.userinfo.userid = res.data.id
					this.userinfo.headicon = '/static/29.jpg'
					this.userinfo.name = res.data.name
				},
				fail: (err) => {
					uni.showToast({
						title: '未登录',
						icon: 'none'
					});
					this.flag = false
				}
			})
		},
		methods: {
			toLogin() {
				uni.navigateTo({
					url: '/pages/my/login'
				})
			},
			logout() {
				// 1. 清理缓存
				uni.clearStorageSync()
				// 2. 修改flag为false
				this.flag = false
				// 3. 清理当前页面的数据 
				this.userinfo = {}
			}
		}
	}
</script>

<style>
.content {
			display: flex;
			flex-direction: column;
			align-items: center;
		}
	
		.head {
			display: flex;
			flex-direction: row;
			align-items: center;
			padding-left: 100rpx;
			align-self: flex-start;
		}
	
		.entry-wrapper {
			margin-top: 100rpx;
			margin-bottom: 80rpx;
			width: 95%;
	
	
		}
	
		.entry-wrapper>view {
			width: 100%;
			height: 3em;
			line-height: 3em;
			border-bottom: 1px solid #ccc;
			text-indent: 1em;
			display: flex;
			flex-direction: row;
			align-items: center;
		}
	
		.entry-wrapper>view>image {
			width: 48rpx;
			height: 48rpx;
		}
	
		.head>image {
			border-radius: 50%;
			width: 100rpx;
			height: 100rpx;
			margin-right: 50rpx;
		}
	
		.head>text {
			margin-top: 30rpx;
		}
	
		.entry-wrapper>view:first-child {
			border-top: 1px solid #ccc;
		}
	
		.button {
			width: 95%;
		}

</style>
